home *** CD-ROM | disk | FTP | other *** search
- /*
- This program is just to perform one array operation
- in order to create a spectrum file in binary float
- */
-
- #include <stdio.h>
- #include <math.h>
- #define _MAXSPCLEN 2048
-
- float x,y,spc[_MAXSPCLEN];
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int n,m,i,max;
- char z[80],comment[80];
- FILE *fp;
-
- for(n=0;n<_MAXSPCLEN;n++) {
-
- x = 0.01 * (n-1024);
- y = 1.0 * exp(-x*x);
-
- spc[n]=y;
- }
- fp=fopen("fnout.spc","w");
- outspec(fp,spc,_MAXSPCLEN,2,"user function");
- fclose(fp);
- }
-
- outspec(stream,spc,max,typ1,s)
- char s[];
- float spc[];
- int max,typ1;
- FILE *stream;
- {
- unsigned char byte1,byte2,byte3,byte4;
- int n,i,typ;
- char c,z[80];
- unsigned long int m;
- union fourbytes {
- float real;
- long int sig;
- unsigned long int card;
- } b4;
-
- fputc(0,stream); fputc(2,stream); /* write type */
- byte1=max/256 ; byte2=max-256*byte1;
- byte2=max & 255 ; byte1=max/256;
- fputc(byte1,stream); fputc(byte2,stream); /* write length in channels */
- for(n=0;n<80;n++) fputc(s[n],stream); /* write comment */
- for(n=1;n<=8;n++) fputc(0,stream); /* 4 spare words */
- for(n=0;n<max;n++) { /* write data */
- b4.real=spc[n]; m=b4.card;
- byte1 = m / 16777216 ;
- m = m - byte1 * 16777216 ;
- byte2 = m / 65536 ;
- m = m - byte2 * 65536 ;
- byte3 = m / 256 ;
- m = m - byte3 * 256 ;
- byte4 = m ;
- fputc(byte1,stream); fputc(byte2,stream);
- fputc(byte3,stream); fputc(byte4,stream);
- }
- }
-